package net.pm.core.aspect;

import javax.annotation.Resource;

import net.pm.core.entities.db.Materiallog;
import net.pm.core.service.MateriallogServicer;

import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
import org.springframework.ui.ModelMap;
import org.springframework.web.servlet.ModelAndView;

/**
 * 物料出入记录
 * @author shizeyuan
 *
 */
@Aspect
@Component
public class PM_03_MateriallogAspect {
	
	@Resource(name="MateriallogServicer")
	private MateriallogServicer materiallogServicer;

	/**
	 * 物料出入记录实体,在modelandview 中的key
	 */
	public static final String MATERIALLOG_KEY = "MATERIALLOG_KEY"; 		
	
	@AfterReturning(value="@annotation(net.pm.core.annotation.MaterialLog)",returning="retval")
	public void comeinAndGetoutRecord(Object retval){
		ModelMap model = ((ModelAndView) retval).getModelMap();
		Materiallog log = (Materiallog) model.get(PM_03_MateriallogAspect.MATERIALLOG_KEY);
		materiallogServicer.create(log);
		model.remove(PM_03_MateriallogAspect.MATERIALLOG_KEY);
	}

}
